// 属性的封装：领属性更安全
(function () {
    /*
        readonly 只读
        static 静态
        public 共有的
        private 私有的  只能在当前类中访问及修改
        若需要更改 则需要在类中定义方法  如可以创建方法getName 与 setName
        protected 受保护的 只能在当前类的子类中访问及使用
    
    */
    class Person {
        // 1.readonly name:string
        // 3.private name:string;
        name: string;
        // 2. static age: number
        age: number
        constructor(name: string, age: number) {
            this.name = name;
            this.age = age;
        }

        getName() {
            return this.name;
        }
        setName(value) {
            return this.name = value
        }
        getAge() {
            return this.age
        }
        setAge(value) {
            if (value) {
                return this.age = value
            }
        }

        /*
        在属性的封装中
        getter 获取属性值 get
        setter 设置属性值 set
        */
        get name1() {
            return this.name;
        }
        set name1(value) {
            this.name = value
        }

    }
    // class A{
    //4. public 
    //     public name:string
    //     public age:number
    //     constructor( name: string,  age: number) {
    //         this.name = name
    //         this.age = age
    //     }
    // }
    class A {
        constructor(public name: string, public age: number) {
            this.name = name
            this.age = age
        }
    }
    class B {
        // 5.protected
        protected num: number;
        constructor(num: number) {
            this.num = num
        }
    }
    class C extends B {
        say() {
            console.log(this.num);

        }
    }

    let c = new C(120);
    console.log(c);
    // c.num=21  protected会报错



    let p = new Person('男', 21)
    // p.name=21;  readonly只读报错
    // Person.age

    console.log(p.getName());
    console.log(p.setName('女'));
    console.log(p.setAge(-22));
    console.log(p.name1);


})()